<template>
  <div>
    <FilterTable
      ref="table"
      columnsRef="fyhRepairPro"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'rows'"
      :height="'auto'"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    ></FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { queryRepairPart, querySellMaterial, queryChargeDifferentiationList } from '@/api/repair/repairReception/repairBusinessManger';
import { getroLabourByestimateNOList } from '@/api/repair/repairReception/evaluation/index';
import { getWxlxSelect } from '@/api/repair/repairReception/customer';
import { getBrand, getSeries, getModel, getRegion, getBxgsSelect } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { searchRoleByCode, searchRoleByCodes } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
export default {
  name: 'repairProSS',
  components: {},
  mixins: [dictionary],
  props: ['dataList', 'ESTIMATE_NO'],
  data() {
    return {
      columns: this.createTableColumns(),
      list: [],
      fetchApi: getroLabourByestimateNOList,
      fetchParams: {},
      selectColumns: []
    };
  },
  created() {
    let roNo = this.ESTIMATE_NO;
    this.fetchParams = Object.assign({}, { code: roNo }, { xhrAbort: false });
  },
  mounted() {
    // this.queryRepairItem(); // 维修项目查询
    this.queryChargeList();
    this.getWxtypeSelect();
    this.querySeries();
  },
  methods: {
    createTableColumns() {
      let that = this;
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: [],
          editable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '故障原因',
          dataIndex: 'TROUBLE_CAUSE',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          defaultEditable: false,
          editType: 'input'
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          // filter: true,
          editable: false,
          defaultEditable: false,
          editType: 'select',
          editItems: []
        },
        {
          title: '项目代码',
          dataIndex: 'LABOUR_CODEF',
          sorter: true
          // filter: true,
          // filterType: 'input'
        },
        {
          title: '项目名称',
          dataIndex: 'LABOUR_NAME',
          width: 200,
          sorter: true,
          // filter: true,
          editable: false,
          showOverflowTooltip: true,
          defaultEditable: false
          // filterType: 'input'
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          editType: 'number',
          defaultEditable: false,
          precision: 2,
          min: 0
        },
        {
          title: '派工工时',
          dataIndex: 'ASSIGN_LABOUR_HOUR',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          editType: 'number',
          defaultEditable: false,
          precision: 0,
          min: 0
        },
        {
          title: '收费工时',
          dataIndex: 'STD_LABOUR_HOUR',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          render: props => {
            return <span>{props.row.STD_LABOUR_HOUR}</span>;
          }
        },
        {
          title: '优惠金额',
          dataIndex: 'DISCOUNT_AMOUNT',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          precision: 2
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          editType: 'number',
          defaultEditable: false,
          maxlength: 4,
          precision: 2,
          min: 0,
          max: 1
        },
        {
          title: '实收金额',
          dataIndex: 'RECEIVE_AMOUNT',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          precision: 2
        },
        {
          title: '工时单价',
          dataIndex: 'LABOUR_PRICE',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          editType: 'number',
          defaultEditable: false,
          precision: 2,
          min: 0
        },
        // {
        //   title: '工种',
        //   dataIndex: 'WORKER_TYPE_CODE',
        //   minWidth: 120,
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: [],
        //   editable: false,
        //   editType: 'select',
        //   editItems: this.createDictList('8041')
        // },
        {
          title: '责任技师',
          dataIndex: 'TECHNICIAN',
          sorter: true
          // filter: true,
          // filterType: 'input'
        },
        {
          title: '是否派工',
          dataIndex: 'ASSIGN_TAG',
          sorter: true,
          // filter: true,
          // filterType: 'checkbox',
          // filterItems: [],
          // filterItems: this.createDictList('1004'),
          render: props => {
            return <span>{this.createDictText(props.row.ASSIGN_TAG, '1004')}</span>;
          }
        },
        // {
        //   title: '是否增项',
        //   dataIndex: 'IS_ADDITION',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'checkbox',
        //   filterItems: [],
        //   filterItems: this.createDictList('1004'),
        //   render: props => {
        //     return <span>{this.createDictText(props.row.IS_ADDITION, '1004')}</span>;
        //   }
        // },
        {
          title: '是否委外',
          dataIndex: 'CONSIGN_EXTERIOR',
          sorter: true,
          editable: false,
          render: props => {
            let val = props.row.CONSIGN_EXTERIOR === '1' ? true : false;
            return <el-checkbox value={val} disabled={props.row.ACTIVITY_CODE || props.row.PACKAGE_CODE ? true : false} onInput={val => (props.row.CONSIGN_EXTERIOR = val ? '1' : '0')}></el-checkbox>;
          }
        },
        // {
        //   title: '是否不修',
        //   dataIndex: 'NEEDLESS_REPAIR',
        //   sorter: true,
        //   editable: false,
        //   defaultEditable: false,
        //   editType: 'checkbox',
        //   editItems: [{ text: '', trueValue: '1' }, { text: '', falseValue: '0' }]
        // },
        // {
        //   title: '不修原因',
        //   dataIndex: 'REASON',
        //   sorter: true,
        //   filter: true,
        //   editable: false,
        //   defaultEditable: false,
        //   editType: 'select',
        //   editItems: this.createDictList('8070')
        // },
        // {
        //   title: '是否预拣',
        //   dataIndex: 'PRE_CHECK',
        //   sorter: true,
        //   editable: false,
        //   render: props => {
        //     let val = props.row.PRE_CHECK === '1' ? true : false;
        //     return <el-checkbox value={val} disabled={props.row.ACTIVITY_CODE || props.row.PACKAGE_CODE ? true : false} onInput={val => (props.row.PRE_CHECK = val ? '1' : '0')}></el-checkbox>;
        //   }
        // },
        {
          title: '是否内返',
          dataIndex: 'INTER_RETURN',
          sorter: true,
          editable: false,
          render: props => {
            let val = props.row.INTER_RETURN === '1' ? true : false;
            return <el-checkbox value={val} disabled={props.row.ACTIVITY_CODE || props.row.PACKAGE_CODE ? true : false} onInput={val => (props.row.INTER_RETURN = val ? '1' : '0')}></el-checkbox>;
          }
        },
        // {
        //   title: '活动编号',
        //   dataIndex: 'ACTIVITY_CODE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '检查结果',
          dataIndex: 'TROUBLE_DESC',
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          defaultEditable: false,
          editType: 'input'
        },
        {
          title: '备注',
          dataIndex: 'REMARK',
          minWidth: 200,
          sorter: true,
          // filter: true,
          // filterType: 'input',
          editable: false,
          defaultEditable: false,
          editType: 'input'
        },
        // {
        //   title: '组合代码',
        //   dataIndex: 'PACKAGE_CODE',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '车系',
          dataIndex: 'MODEL_LABOUR_CODE',
          minWidth: 200,
          sorter: true,
          // filter: true,
          // filterType: 'input',
          showOverflowTooltip: true,
          editType: 'select',
          editItems: []
        },
        // {
        //   title: '钣喷面积',
        //   dataIndex: 'SPRAY_AREA',
        //   sorter: true,
        //   filter: true,
        //   filterType: 'input'
        // },
        {
          title: '故障部位',
          dataIndex: 'POS_NAME',
          sorter: true
          // filter: true,
          // filterType: 'input'
        },
        {
          title: '故障',
          dataIndex: 'APP_NAME',
          sorter: true
          // filter: true,
          // filterType: 'input'
        }
      ];
    },

    // 查询收费区分
    async queryChargeList() {
      const res = await queryChargeDifferentiationList();
      // console.log(res, 'res');
      this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').editItems = this.columns.find(x => x.dataIndex === 'CHARGE_PARTITION_CODE').filterItems = res.data.map(x => ({
        value: x.CHARGE_PARTITION_CODE + '',
        text: x.CHARGE_PARTITION_NAME
      }));
    },

    // 查询所有车系(供table使用)
    async querySeries() {
      const res = await getSeries();
      this.columns.find(x => x.dataIndex === 'MODEL_LABOUR_CODE').editItems = res.data.map(x => ({ text: x.SERIES_NAME, value: x.SERIES_ID + '' }));
    },

    // 查询维修项目
    // async queryRepairItem() {
    //   const roNo = this.roNo;
    //   const res = (await queryRepairLabour(roNo)).data.rows;
    //   this.list = res;
    // },

    // 获取维修项目类型
    async getWxtypeSelect() {
      const res = await getWxlxSelect();
      this.columns.find(x => x.dataIndex === 'REPAIR_TYPE_CODE').editItems = res.data.map(x => ({
        value: x.REPAIR_TYPE_CODE + '',
        text: x.REPAIR_TYPE_NAME
      }));
    },

    // 售前人员接口数据
    async serviceConsultant() {
      // let consultant = { role: dictCode.SERVICE_CONSULTANT }; // 服务顾问
      let technician = { role: dictCode.TECHNICIAN }; // 指定技师
      // const consultantRes = await searchRoleByCode(consultant);
      const technicianRes = await searchRoleByCodes(technician);
      // this.topFilterList.find(x => x.fieldName === 'serviceAdvisor').itemList = consultantRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
      this.columns.find(x => x.dataIndex === 'TECHNICIAN').editItems = technicianRes.data.map(x => ({ text: x.employeeName, value: x.userId + '' }));
    },

    createBaseTable() {
      this.BaseTable = this.$refs.table.$refs.pageTable;
    }
    // // 传给父组件
    // syncTableFun(val) {
    //   if (val && val.length > 0) {
    //     delete val.dataMark;
    //     this.$emit('syncTablelist', val);
    //   } else {
    //     this.$emit('syncTablelist', []);
    //   }
    // },
  }
};
</script>

<style lang="less"></style>
